<!doctype html>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>登录 / 注册</title>
    <meta name="description"
          content="Hurst – Furniture Store eCommerce HTML Template is a clean and elegant design – suitable for selling flower, cookery, accessories, fashion, high fashion, accessories, digital, kids, watches, jewelries, shoes, kids, furniture, sports….. It has a fully responsive width adjusts automatically to any screen size or resolution.">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="shortcut icon" type="image/x-icon" href="assets/picture/favicon.ico">
    <!-- Place favicon.ico in the root directory -->

    <!-- Google Font -->
    <link href='https://fonts.googleapis.com/css?family=Lato:400,700,900' rel='stylesheet' type='text/css'>
    <link href='https://fonts.googleapis.com/css?family=Bree+Serif' rel='stylesheet' type='text/css'>

    <!-- all css here -->
    <!-- bootstrap v3.3.6 css -->
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <!-- animate css -->
    <link rel="stylesheet" href="assets/css/animate.min.css">
    <!-- jquery-ui.min css -->
    <link rel="stylesheet" href="assets/css/jquery-ui.min.css">
    <!-- meanmenu css -->
    <link rel="stylesheet" href="assets/css/meanmenu.min.css">
    <!-- nivo-slider css -->
    <link rel="stylesheet" href="assets/css/nivo-slider.css">
    <link rel="stylesheet" href="assets/css/preview.css">
    <!-- slick css -->
    <link rel="stylesheet" href="assets/css/slick.min.css">
    <!-- lightbox css -->
    <link rel="stylesheet" href="assets/css/lightbox.min.css">
    <!-- material-design-iconic-font css -->
    <link rel="stylesheet" href="assets/css/material-design-iconic-font.css">
    <!-- All common css of theme -->
    <link rel="stylesheet" href="assets/css/default.css">
    <!-- style css -->
    <link rel="stylesheet" href="assets/css/style.min.css">
    <!-- shortcode css -->
    <link rel="stylesheet" href="assets/css/shortcode.css">
    <!-- responsive css -->
    <link rel="stylesheet" href="assets/css/responsive.css">
    <!-- modernizr css -->
    <script src="assets/js/modernizr-3.11.2.min.js"></script>
</head>
<body>
<!-- WRAPPER START -->
<div class="wrapper bg-dark-white">

    <!-- HEADER-AREA START -->
    <header id="sticky-menu" class="header header-2">
        <div class="header-area">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-4 offset-md-4 col-7">
                        <div class="logo text-md-center">
                            <a href="index.html"><img src="assets/picture/logo.png" alt=""></a>
                        </div>
                    </div>
                    <div class="col-md-4 col-5">

                    </div>
                </div>
            </div>
        </div>
    </header>
    <!-- HEADER-AREA END -->
    <!-- Mobile-menu start -->

    <!-- Mobile-menu end -->
    <!-- HEADING-BANNER START -->
    <div class="heading-banner-area overlay-bg">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="heading-banner">
                        <div class="heading-banner-title">
                            <h2>登册页面</h2>
                        </div>
                        <div class="breadcumbs pb-15">
                            <ul>
                                <li><a href="index.html">主页</a></li>
                                <li>登册</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- HEADING-BANNER END -->
    <!-- SHOPPING-CART-AREA START -->
    <div class="login-area  pt-80 pb-80">
        <div class="container">
            <!--					<form action="javascript:;">	-->
            <div class="row">
                <div class="col-lg-6" id="loginForm">
                    <form class="customer-login">
                        <div class="customer-login text-left">
                            <h4 class="title-1 title-border text-uppercase mb-30">游客登录</h4>
                            <p class="text-gray">如果您有账号，请直接登录！</p>
                            <input type="text" placeholder="用户名" name="username" id="username">
                            <input type="password" placeholder="密码" id="password">
                            <p>
                                <button class="text-gray" onclick="NoForget()" id="forget">忘记密码？</button>
                            </p>
                            <button id="loginBtn" type="submit" data-text="登录"
                                    class="button-one submit-button mt-15"
                                    onclick="">login
                            </button>
                        </div>
                    </form>
                </div>
                <div class="col-lg-6">
                    <form class="customer-login" id="registerForm">
                        <div class="customer-login text-left">
                            <h4 class="title-1 title-border text-uppercase mb-30">新用户</h4>
                            <p class="text-gray">如果您有账号，请直接登录！</p>
                            <input type="text" placeholder="你的名字" name="name">
                            <input type="text" placeholder="用户名" name="r_username">
                            <input type="password" placeholder="密码" name="r_password">
                            <input type="password" placeholder="请确认密码" name="confirmPassword">
                            <p class="mb-0">
                                <input type="checkbox" id="newsletter" name="newsletter" checked>
                                <label for="newsletter"><span>请阅读协议并同意</span></label>
                            </p>
                            <button type="submit" data-text="注册" class="button-one submit-button mt-15">register
                            </button>
                        </div>
                    </form>
                </div>
            </div>
            <!--					</form>-->
        </div>
    </div>
    <!-- SHOPPING-CART-AREA END -->
    <!-- FOOTER START -->
    <!-- END QUICKVIEW PRODUCT -->

</div>
<!-- WRAPPER END -->

<!-- all js here -->
<!-- jquery latest version -->
<script src="assets/js/jquery-3.6.0.min.js"></script>
<script src="assets/js/jquery-migrate-3.3.2.min.js"></script>
<!-- bootstrap js -->
<script src="assets/js/bootstrap.bundle.min.js"></script>
<!-- jquery.meanmenu js -->
<script src="assets/js/jquery.meanmenu.js"></script>
<!-- slick.min js -->
<script src="assets/js/slick.min.js"></script>
<!-- jquery.treeview js -->
<script src="assets/js/jquery.treeview.js"></script>
<!-- lightbox.min js -->
<script src="assets/js/lightbox.min.js"></script>
<!-- jquery-ui js -->
<script src="assets/js/jquery-ui.min.js"></script>
<!-- jquery.nivo.slider js -->
<script src="assets/js/jquery.nivo.slider.js"></script>
<script src="assets/js/home.js"></script>
<!-- jquery.nicescroll.min js -->
<script src="assets/js/jquery.nicescroll.min.js"></script>
<!-- countdon.min js -->
<script src="assets/js/countdon.min.js"></script>
<!-- wow js -->
<script src="assets/js/wow.min.js"></script>
<!-- plugins js -->
<script src="assets/js/plugins.js"></script>
<!-- main js -->
<script src="assets/js/main.min.js"></script>

<script>
    //token验证
    fetch('user/login', {
        method: 'GET',
        // headers: {
        //     'Authorization': 'Bearer' + localStorage.getItem('token')
        // }
    }).then(response => response.json()).then(result => console.log(result));

    // fetch('user/register', {
    //     method: 'GET',
    //     headers: {
    //         'Authorization': 'Bearer' + localStorage.getItem('token')
    //     }
    // }).then(response => response.json()).then(result => console.log(result));


    $(document).ready(function () {
        // 登录表单提交
        $("#loginBtn").click(function () {


            var username = $("#username").val();
            var password = $("#password").val();
            $.ajax({
                url: "/user/login",
                type: "POST",
                contentType: 'application/json;charset=UTF-8',
                data: JSON.stringify({
                    username: username,
                    password: password
                }),
                success: function (response) {
                    if (response.success) {
                        // localStorage.setItem('token', response.token);
                        alert("登录成功！");
                        window.location.href = "/index.html";
                    } else {
                        console.log("Username:", username);
                        console.log("Password:", password);
                        alert("登录失败: " + response.message);
                    }
                },
                error: function (xhr, status, error) {
                    console.log("Username2:", username);
                    console.log("Password2:", password);
                    alert("登录失败: " + (xhr.message || "用户名或密码错误"));
                }
            });
            $("#forget").on("click", function () {
                alert("不准忘");
            });
        });

        // 注册表单提交
        $("#registerForm").on("submit", function (e) {
            e.preventDefault();

            var r_password = $("input[name='r_password']").val();
            var confirmPassword = $("input[name='confirmPassword']").val();

            if (r_password !== confirmPassword) {
                alert("两次输入的密码不一致");
                return;
            }

            if (!$("#newsletter").is(":checked")) {
                alert("请同意用户协议");
                return;
            }

            var formData = $(this).serialize();

            $.ajax({
                url: "/user/register",
                type: "POST",
                data: formData,
                success: function (response) {
                    if (response.success) {
                        alert("注册成功！请登录");
                        $("#registerForm")[0].reset();
                    } else {
                        alert("注册失败: " + response.message);
                    }
                },
                error: function (xhr, status, error) {
                    alert("注册失败: " + (xhr.message || "服务器错误"));
                }
            });
        });
    });


</script>


</body>
</html>
